Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
graphology-shortest-path
Advanced tools
Shortest path functions for graphology
.
npm install graphology-shortest-path
Returns the shortest path in the graph between source & target or null
if such a path does not exist.
import {bidirectional} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import {bidirectional} from 'graphology-shortest-path/unweighted';
// Returning the shortest path between source & target
const path = bidirectional(graph, source, target);
Arguments
graphology
instance.Return a map of every shortest path between the given source & all the nodes of the graph.
import {singleSource} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import {singleSource} from 'graphology-shortest-path/unweighted';
// Returning every shortest path between source & every node of the graph
const paths = singleSource(graph, source);
Arguments
graphology
instance.Return a map of every shortest path length between the given source & all the nodes of the graph.
import {singleSourceLength} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import {singleSourceLength} from 'graphology-shortest-path/unweighted';
// Returning every shortest path between source & every node of the graph
const paths = singleSourceLength(graph, source);
Arguments
graphology
instance.Return a map of every shortest path length between the given source & all the nodes of the graph. This is basically the same as singleSourceLength except that it will consider any given graph as undirected when traversing.
import {undirectedSingleSourceLength} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import {undirectedSingleSourceLength} from 'graphology-shortest-path/unweighted';
// Returning every shortest path between source & every node of the graph
const paths = undirectedSingleSourceLength(graph, source);
Arguments
graphology
instance.Returns the shortest path in the weighted graph between source & target or null
if such a path does not exist.
import {dijkstra} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import dijkstra from 'graphology-shortest-path/dijkstra';
// Returning the shortest path between source & target
const path = dijkstra.bidirectional(graph, source, target);
// If you store edges' weight in custom attribute
const path = dijkstra.bidirectional(graph, source, target, 'customWeight');
// Using a custom weight getter function
const path = dijkstra.bidirectional(
graph,
source,
target,
(_, attr) => attr.importance
);
Arguments
graphology
instance.weight
]: name of the weight attribute or getter function.Return a map of every shortest path between the given source & all the nodes of the weighted graph.
import {dijkstra} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import dijkstra from 'graphology-shortest-path/dijkstra';
// Returning every shortest path between source & every node of the graph
const paths = dijkstra.singleSource(graph, source);
// If you store edges' weight in custom attribute
const paths = dijkstra.singleSource(graph, source, 'customWeight');
// Using a custom weight getter function
const path = dijkstra.singleSource(graph, source, (_, attr) => attr.importance);
Arguments
graphology
instance.weight
]: name of the weight attribute or getter function.Returns the shortest path in the weighted graph between source & target or null
if such a path does not exist.
import {astar} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import astar from 'graphology-shortest-path/astar';
// Returning the shortest path between source & target
const path = astar.bidirectional(
graph,
source,
target,
(_, attr) => attr.importance
(node, finalTarget) => euclideanDistance(points[node], points[finalTarget])
);
Arguments
graphology
instance.weight
]: name of the weight attribute or getter function.Helper function that can convert a node path to an edge path.
import {edgePathFromNodePath} from 'graphology-shortest-path';
// Alternatively, if you want to load only the relevant code
import {edgePathFromNodePath} from 'graphology-shortest-path/utils';
const edgePath = edgePathFromNodePath(graph, nodePath);
Arguments
graphology
instance.FAQs
Shortest path functions for graphology.
The npm package graphology-shortest-path receives a total of 24,083 weekly downloads. As such, graphology-shortest-path popularity was classified as popular.
We found that graphology-shortest-path demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.